"""
fcObjects.py defines first class objects
if not yet defined,
otherwise, it loads them for use
"""

# open a users.json file
# create an object from it
import json, sys

"""
with open("users.json", "r") as jsonfile:
    userdata = json.load(jsonfile)
    # print userdata["users"][0]["group"]
    print userdata
"""


class fco(object):
    def __init__(self):
        self.version = "0.1"
        self.data = {} # need to initialize this
        self.jsonFiles = { "users": "users.json", "groups": "groups.json" }
        self.loadObjects()

    def loadObjects(self):
        try:
            for key in self.jsonFiles.keys():
                with open(self.jsonFiles[key], "r") as jsonfile:
                    self.data[key] = json.load(jsonfile)
                    # to test, simply do something like one of these
                    # print fco.userdata["users"][0]["group"]
                    # print fco.userdata["users"][0]["group"]
        except:
            print sys.exc_info()

    

if __name__ == "__main__":
    testfco = fco()
    print "Database version is ", testfco.version
    print "printing user data:"
    from pprint import pprint
    pprint(testfco.data)
